import { useState } from "react";
import { Button, Popconfirm } from "antd";
import { ClearOutlined } from '@ant-design/icons'

import type { ExtendOperatorComponent } from "@yaf/pro-ui";
import { clearOperLog } from "../../api";

export const getClearLogBtn = (): ExtendOperatorComponent => ({ doFetchList, clearSelected }) => {
  const [loading, setLoading] = useState(false);

  return <Popconfirm
    title="确定清除所有日志吗?"
    onConfirm={() => {
      setLoading(true);
      clearOperLog().then(() => {
        setLoading(false);
        clearSelected();
        doFetchList();
      }).catch(() => {
        doFetchList();
        setLoading(false)
      })
    }}
  >
    <Button type="primary" loading={loading} icon={<ClearOutlined />} danger>清除</Button>
  </Popconfirm>
}
